cd E:\data\合作研究\产学研\绿色金融\data
use data_finance,clear

*************Table 1**********************
//表格1
sum strong_co2   credit security lrgdp RD feffic l_population  urban  l_fdi eg  l_tech stru_ration rely

des  strong_co2   credit security lrgdp RD feffic l_population  urban  l_fdi eg  l_tech stru_ration rely 


//表格2

xtunitroot fisher D.strong_co2 ,pperron lags(2)
xtunitroot fisher D.credit ,pperron lags(2)

************多重共线性***********
//表格3
collin credit security lrgdp RD feffic l_population  urban  l_fdi eg l_tech stru_ration
des credit security lrgdp RD feffic l_population  urban  l_fdi eg l_tech stru_ration

**********表格4******



xtreg strong_co2  credit lrgdp RD feffic l_population  urban  l_fdi eg  ,fe
est store reg1
xtreg strong_co2 credit lrgdp RD feffic l_population  urban  l_fdi eg,re
est store reg2 
xtreg strong_co2  credit lrgdp RD feffic l_population  urban  l_fdi eg   i.year,fe
est store reg5
xtreg strong_co2  L.credit D.credit  lrgdp RD feffic l_population  urban  l_fdi eg i.year,fe
est store reg3
xtabond2  L(0/1).strong_co2 credit lrgdp RD feffic l_population  urban  l_fdi eg,gmm(L.strong_co2 credit ) twostep small h(2)
est store reg4
esttab  reg1 reg2 reg5 reg3 reg4   , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30) varlabels(_cons 截距) mtitles("FE" "RE" "FE" "GMM") /// 
keep (L.strong_co2 L.credit D.credit  lrgdp RD feffic l_population  urban  l_fdi eg _cons) ///
stats(N r2, fmt(0 4) label(观察值 R方 )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/
hausman reg1 reg2,sigmaless



//稳健性
xtreg strong_co2  security  lrgdp RD feffic l_population  urban  l_fdi eg ,fe
est store reg1
xtreg strong_co2 security  lrgdp RD feffic l_population  urban  l_fdi eg ,re
est store reg2
xtreg strong_co2  L.security D.security  lrgdp RD feffic l_population  urban  l_fdi eg ,fe
est store reg3

xtivreg strong_co2 (credit= L.credit y02 )  lrgdp RD feffic l_population  urban  l_fdi eg ,fe
xtoverid
dmexogxt
est store reg4
esttab  reg1 reg2 reg3   reg4 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30) varlabels(_cons 截距) mtitles("FE" "RE" "FE" "GMM") /// 
stats(N r2, fmt(0 4) label(观察值 R方 )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/
hausman reg1 reg2,sigmaless

gen l_gdp= ln(gdp)

**************中介效应****************************
//table 6

xtreg l_tech  credit  lrgdp RD feffic l_population  urban  l_fdi eg ,fe
est store reg1
 
xtreg strong_co2  credit l_tech lrgdp RD feffic l_population  urban  l_fdi eg ,fe
est store reg2
xtreg stru_ration  credit lrgdp RD feffic l_population  urban  l_fdi eg,fe
est store reg3
 
xtreg strong_co2  credit stru_ration lrgdp RD feffic l_population  urban  l_fdi eg,fe
est store reg4

xtreg strong_co2  credit l_tech stru_ration lrgdp RD feffic l_population  urban  l_fdi eg,fe
est store reg5
esttab  reg1 reg2 reg3 reg4  reg5 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30) varlabels(_cons 截距) mtitles("FE" "RE" "FE" "GMM") /// 
stats(N r2, fmt(0 4) label(观察值 R方 )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/

capture program drop bootm1
program bootm1, rclass
   xtreg l_tech  credit  lrgdp RD feffic l_population  urban  l_fdi eg ,fe
   matrix a=e(b)
   scalar a1 =a[1,1]
   xtreg stru_ration  credit lrgdp RD feffic l_population  urban  l_fdi eg,fe
   matrix a=e(b)
   scalar a2 =a[1,1]
   xtreg strong_co2  credit l_tech stru_ration lrgdp RD feffic l_population  urban  l_fdi eg,fe
   matrix a=e(b)
   scalar a3 =a[1,2]
   scalar a4 =a[1,3]
   return scalar low=a1*a3
   return scalar high=a2*a4
end
bootstrap r(low) r(high) , reps(500) seed(1234) nodots: bootm1 //路径二（绿色信贷—技术创新—碳排放强度  (控制产业结构升级)）


*************能源依赖的调节作用********************

tabstat rely, stats (sd median range mean)
gen level_rely=0
replace level_rely=1 if rely>=3
gen egov_rely=credit*level_rely
xtreg strong_co2   credit   lrgdp RD feffic l_population  urban  l_fdi eg if level_rely==0,fe
est store reg1
xtreg strong_co2   credit   lrgdp RD feffic l_population  urban  l_fdi eg if level_rely==1,fe
est store reg2
xtreg strong_co2   credit egov_rely  level_rely lrgdp RD feffic l_population  urban  l_fdi eg,fe
est store reg3
esttab  reg1 reg2 reg3    , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30) varlabels(_cons 截距) mtitles("FE" "RE" "FE" "GMM") /// 
stats(N r2, fmt(0 4) label(观察值 R方 )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/